package com.obixlabs.security.credentialsstore.model;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.xml.bind.annotation.XmlAttribute;

@MappedSuperclass
public class User extends BaseUser
{
	private static final long serialVersionUID = -231330616016726650L;
	
	@Basic(optional=false)
	@Column(name="first_name",length=50, nullable=false)	
	private String firstName;
	
	@Basic(optional=false)
	@Column(name="last_name",length=50, nullable=false)	
	private String lastName;
	
	public User(){}
	
	@XmlAttribute
	public String getFirstName(){return firstName;}
	public void setFirstName(String firstName)
	{this.firstName = firstName;}
	
	@XmlAttribute
	public String getLastName(){return lastName;}
	public void setLastName(String lastName)
	{this.lastName = lastName;}

	@Override
	public int hashCode()
	{
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result
				+ ((firstName == null) ? 0 : firstName.hashCode());
		result = prime * result
				+ ((lastName == null) ? 0 : lastName.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj)
	{
		if (this == obj) return true;
		
		if (!super.equals(obj)) return false;
		
		if (!(obj instanceof User)) return false;
		
		User other = (User) obj;
				
		if (getFirstName() == null) {
			if (other.getFirstName() != null) return false;
		} else if (!getFirstName().equals(other.getFirstName())) return false;
		
		if (getLastName() == null) {
			if (other.getLastName() != null) return false;
		} else if (!getLastName().equals(other.getLastName())) return false;
				
		return true;
	}			
}
